<?php
@session_start();
$PurviewLevel=2;
$CheckChannelID=0;
require("../../inc/common.inc.php");
$usersql="";
$type=intval($type);
if ($type==2){
	$PurviewLevel_Others="yingxiao_hudong_choujiang";
}
elseif ($type==3){
	$PurviewLevel_Others="yingxiao_hudong_guaguale";
}
else{
	$type=1;
	$PurviewLevel_Others="yingxiao_hudong_zhuanpan";
}
$usersql=" and type='$type' ";
require_once("../Admin_ChkPurview.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<TITLE>铭讯EOS网站后台管理</TITLE>
<Meta name="Keywords" Content="济南网站建设 济南网站制作 山东网站建设 济南铭讯软件有限公司">
<Meta name="Description" Content="济南网站制作：铭讯软件专业服务优秀企业，致力于网站建、设网站推广、网络营销一体的全访位网络服务商">
<link rel="stylesheet" href="../images/style.css" type="text/css">
</head>
<body> 
<div class="right">
<?php
require("../mx_head.php");
switch ($type) {
	case '1': $typename = '大转盘'; break;
	case '2': $typename = '抽奖';   break;
	case '3': $typename = '刮刮乐'; break;
}
if ($action=="work"){
    //设置推荐
	if(!$listdb&&!$id){
		$fun->popmassage("请选择一个".$typename,"","popback");
		exit();
	}
	elseif(is_array($listdb))
	{
		foreach($listdb AS $key=>$value){
			dowork($key,$jobs);
		}
	}elseif($id){
		dowork($id,$jobs);
	}
	$url=$fromurl?$fromurl:$FROMURL;
	jump2("操作成功",$url,1);
	exit();
} elseif($actions=="delpic"){
	if(!$id){
		$fun->popmassage("请选择要删除的图片","","popback");
		exit();
	}
	$pic=$db->getsingle("select picurl from mx_vpp_caipiao WHERE id='$id' $usersql");
	if ($pic!=""){@unlink("../../$webdb[updir]$pic");}
	//删除附件
	$db->excu("update mx_vpp_caipiao set picurl='' WHERE id='$id' $usersql");
	$url="yx_vpp_caipiao.php?type=$type&id=$id&action=edit";
	
	jump2("操作成功",$url,1);
	exit();
} else if ($action == 'add' || $action == 'edit') {
    if ($action == 'edit') {
		$rsdb=$db->get_one("SELECT * FROM mx_vpp_caipiao WHERE id='$id' $usersql limit 1");
		if ($rsdb=="" || empty($rsdb)){
		  $fun->popmassage("非法访问，系统将自动返回上一页！","","popback");
		  exit();
		}
		$isok[$rsdb[isok]]="checked";
	}
	$postaction = $action == 'add' ? 'saveadd' : 'saveedit';
    if ($gotourl==""){$gotourl=url_encode($_SERVER['HTTP_REFERER']);}
?>
<script language="javascript">
<!--
function dianji(){
  if(document.siteForm.name.value==""){
    alert("名称不能为空！");
	document.siteForm.name.focus();
	return false;
  }
}
-->
</script>
<div class="xm2">
<h1 class="fl">修改信息</h1>
</div>
<div class="xm2_b">
<div class="height10"></div>
<div class="n_div" style="width:100%;">
<table width="100%" border="0" cellspacing="1" cellpadding="5" class="table_southidc">
<form name="siteForm" method="post" action="yx_vpp_caipiao.php" id="form1" enctype="multipart/form-data">
<input type="hidden" name="postdb[id]" value="<?php echo $rsdb[id] ?>">
<input type="hidden" name="type" value="<?php echo $type ? $type : $rsdb[type] ?>">
<tr class="list">
  <td width="130" align="right"><strong><?php echo $typename ?>名称：</strong></td>
  <td><input type="text" name="postdb[name]" id="name" value="<?php echo $rsdb[name] ?>" size="50"></td>
</tr>
<tr class="list">
  <td width="130" align="right"><strong>开始时间：</strong></td>
  <td><label> <input type="text" name="postdb[startdate]" size="10" id="startdate" value="<?php echo $rsdb[startdate] ?>">
      <script language="javascript" type="text/javascript">
	  Calendar.setup({
	  	  inputField     :    "startdate",
	  	  ifFormat       :    "%Y-%m-%d",
	  	  showsTime      :    false,
	  	  timeFormat     :    "24"
	  });
	  </script>
      </label>
   </td>
</tr>
<tr class="list">
  <td width="130" align="right"><strong>结束时间：</strong></td>
  <td><label> <input type="text" name="postdb[enddate]" size="10" id="enddate" value="<?php echo $rsdb[enddate] ?>">
      <script language="javascript" type="text/javascript">
	  Calendar.setup({
	  	  inputField     :    "enddate",
	  	  ifFormat       :    "%Y-%m-%d",
	  	  showsTime      :    false,
	  	  timeFormat     :    "24"
	  });
	  </script>
      </label>
  </td>
</tr>
<?php //if ($type == 1) { ?>
<tr class="list">
  <td width="130" align="right"><font color="#FF0000"><strong>缩 略 图：</strong></font></td>
  <td><input name="picurl" type="file" /><input type="hidden" name="postdb[oldpicurl]" value="<?php echo $rsdb[picurl]?>">&nbsp;标准图片尺寸：480px*270px，不修改时请留空</td>
</tr>
<?php if(trim($rsdb[picurl])!=""){?>
<tr class="list">
  <td width="130" align="right"></td>
  <td><img src="<?php echo "$webdb[updir]$rsdb[picurl]" ?>" height="140">&nbsp;<a href="yx_vpp_caipiao.php?actions=delpic&id=<?php echo $rsdb["id"]?>&type=<?php echo $type ?>">删除图片</a></td>
</tr>
<?php 
}
//}
?>

<tr class="list">
  <td width="130" align="right"><strong><?php echo $typename ?>简介：</strong></td>
  <td><label>
    <textarea name="postdb[description]" cols="70" rows="3"><?php echo dvhtmlcode($rsdb[description]) ?></textarea></label>
  </td>
</tr>
<tr class="list">
  <td width="130" align="right"><strong>每天次数：</strong></td>
  <td><label><input type="text" name="postdb[usernum]" size="30" value="<?php echo $rsdb["usernum"] > 0 ? $rsdb["usernum"] : 1; ?>"></label>
  </td>
</tr>
<tr class="list">
  <td width="130" align="right"><strong>消耗积分：</strong></td>
  <td><label><input type="text" name="postdb[needintegral]" size="30" value="<?php echo $rsdb["needintegral"] > 0 ? $rsdb["needintegral"] : 0; ?>"></label>
  </td>
</tr>
<tr class="list">
  <td width="130" align="right"><strong>排序：</strong></td>
  <td><label><input type="text" name="postdb[orderid]" size="30" value="<?php echo $rsdb["orderid"] > 0 ? $rsdb["orderid"] : 666; ?>"></label>
  </td>
</tr>
<?php if ($Purview==1 or strpos("****".$OtherPurview,'yingxiao_vpp_yhq')>0){?>
<tr class="list">
  <td width="130" align="right"><strong>立即发布：</strong></td>
  <td>
	 <input name="postdb[isok]" type="checkbox" value="1" class="input_check" <?php echo $isok[1]?>>
     是<font color="#0000FF">（如果选中的话将直接发布，否则审核后才能发布。）</font> </td>
 </tr>
<?php }?>
<tr class="list">
  <td height="40" align="center" valign="bottom" colspan="2">
      <label>
	    <input type="hidden" name="url" value="<?php echo $gotourl?>">
	    <input type="hidden" name="action" value="<?php echo $postaction ?>">
        <input type="submit" name="Submit" value="提 交" class="button" /> 
        &nbsp;&nbsp;
      <input type="reset" name="button" value="取 消" class="button2"/>
      </label></td>
</tr>
</form>
</table>
<div class="clear"></div>
<div class="height10"></div>
</div>
<div class="height10"></div>
</div>
<?php
    exit ();
} elseif ($action == 'saveadd') {
	if (strpos("****".$OtherPurview,'yingxiao_vpp_yhq')<=0 and $Purview!=1){
		    $fun->popmassage("您没有此项管理权限","","popback");
		    exit();
		}
	if ($postdb[name]=="" || empty($postdb[name])){
		$fun->popmassage("请填写".$typename."名称","","popback");
		exit();
	}
	
	$file=$_FILES['picurl'];
	if (!empty($file["name"])){
	$iname = date("YmdHis");
	$picType = explode(".",$_FILES["picurl"]["name"]);
			$picType = $picType[1];		
			$picPath = "../../{$webdb[updir]}/vppdazhuanpan/".date("Ym")."/".$iname.".".$picType;
			$img="vppdazhuanpan/".date("Ym")."/".$iname.".".$picType;
			movefile("","","../../{$webdb[updir]}/vppdazhuanpan/".date("Ym")."/");
			if(move_uploaded_file($_FILES['picurl']['tmp_name'], $picPath))
			{
				chmod($picPath,0777);
			}else{
			/*print_r($_FILES["file"]);*/
			}	
	}
	
	$postdb[isok]=intval($postdb[isok]);
	$sql = "INSERT INTO `mx_vpp_caipiao` 
	(`name` ,`description` ,picurl ,`startdate` ,`enddate` ,`usernum` ,`needintegral` ,`addid` ,`createdate` ,`updateid` ,`updatedate` ,`isok` ,`orderid` ,`type`)
	VALUES 
	('$postdb[name]', '$postdb[description]', '$img', '$postdb[startdate]', '$postdb[enddate]', '$postdb[usernum]', '$postdb[needintegral]', '".$_SESSION['mxadmin']['userid']."', '".date("Y-m-d H:i:s",time())."', '".$_SESSION['mxadmin']['userid']."', '".date("Y-m-d H:i:s",time())."', '$postdb[isok]', '$postdb[orderid]', '$type')";
	$db->excu($sql);

	$url=url_code($url);
	jump2("操作成功","$url",2);
	exit ();
} else if ($action == 'saveedit') {
	if ($postdb[id]=="" || empty($postdb[id])){
		$fun->popmassage("请选择一个".$typename,"","popback");
		exit();
    }

	$ainfo=$db->getinfo("select * from mx_vpp_caipiao where id='$postdb[id]' $usersql ");
	if (!is_array($ainfo)){
		$fun->popmassage("请选择要修改的信息","","popback");
		exit();
	}

	$file=$_FILES['picurl'];
	if (!empty($file["name"])){
	$iname = date("YmdHis");
	$picType = explode(".",$_FILES["picurl"]["name"]);
			$picType = $picType[1];		
			$picPath = "../../{$webdb[updir]}/vppdazhuanpan/".date("Ym")."/".$iname.".".$picType;
			$img="vppdazhuanpan/".date("Ym")."/".$iname.".".$picType;
			movefile("","","../../{$webdb[updir]}/vppdazhuanpan/".date("Ym")."/");
			if(move_uploaded_file($_FILES['picurl']['tmp_name'], $picPath))
			{
				chmod($picPath,0755);
			}else{
			}	
			@unlink("../../$webdb[updir]/$postdb[oldpicurl]");
	}
	else{
		$img=$postdb[oldpicurl];
	}

	$addsql="";
	$postdb[isok]=intval($postdb[isok]);
/*		
	if ($Purview==1 or strpos("****".$OtherPurview,'yingxiao_vpp_yhq')>0){
		$addsql=",isok='$postdb[isok]',yzid='".$_SESSION['mxadmin']['userid']."',yzdate='".date("Y-m-d H:i:s")."'";
	}
	else{
		$addsql=",isok='$postdb[isok]'";
	}
*/
	$sql = "UPDATE `mx_vpp_caipiao` SET 
	`name` = '$postdb[name]',`description` = '$postdb[description]',`picurl` = '$img',`startdate` = '$postdb[startdate]',`enddate` = '$postdb[enddate]',`usernum` = '$postdb[usernum]',`needintegral` = '$postdb[needintegral]',`updateid` = '".$_SESSION['mxadmin']['userid']."',`updatedate` = '".date("Y-m-d H:i:s",time())."', `isok` = '$postdb[isok]',`orderid` = '$postdb[orderid]' WHERE `id` = '$postdb[id]' $usersql ";
	$db->excu($sql);
    $url=url_code($url);
	jump2("操作成功","$url",2);
	exit ();
}

function dowork($id,$job){
	global $db,$pre,$timestamp,$userdb,$webdb,$fiddbadmin,$Purview,$fun,$OtherPurview,$Purview,$usersql;
	if ($Purview!=1){$jobwhere.=" $newsfidsql "; }
	if($job=="delete")
	{
	    if (strpos("****".$OtherPurview,'shenhe')<=0 and $Purview!=1){
		    $fun->popmassage("您没有此项管理权限","","popback");
		    exit();
		}
		$db->excu("delete from mx_vpp_caipiao  WHERE id='$id' $usersql");
	}
	elseif($job=="isok")
	{
	    if (strpos("****".$OtherPurview,'shenhe')<=0 and $Purview!=1){
		    $fun->popmassage("您没有此项管理权限","","popback");
		    exit();
		}
		$db->excu("UPDATE mx_vpp_caipiao SET isok='1',updateid='".$_SESSION['mxadmin']['userid']."',updatedate='".date("Y-m-d H:i:s")."' WHERE id='$id'  $jobwhere $usersql ");
	}
	elseif($job=="unisok")
	{
	    if (strpos("****".$OtherPurview,'shenhe')<=0 and $Purview!=1){
		    $fun->popmassage("您没有此项管理权限","","popback");
		    exit();
		}
		$db->excu("UPDATE mx_vpp_caipiao SET isok='0',updateid='".$_SESSION['mxadmin']['userid']."',updatedate='".date("Y-m-d H:i:s")."' WHERE id='$id' $jobwhere $usersql");
	}
}
?>
<div class="gk">
    <div class="ti2 fl">信息管理</div>
    <ul class="fr">
        <li><span class="c1"><?php $znum=$db->listcount("mx_vpp_caipiao"," and type=".$type);echo $znum;?></span><span>总条数</span></li>
        <li class="line"></li>
        <li><span class="c2"><?php $znum=$db->listcount("mx_vpp_caipiao"," and isok='1' and type=".$type);echo $znum;?></span><span>已审核</span></li>
        <li class="line"></li>
        <li><span class="c3"><?php $znum=$db->listcount("mx_vpp_caipiao"," and isok='0' and type=".$type);echo $znum;?></span><span>未审核</span></li>
    </ul>
    <div class="clear"></div>
</div>
<div class="height15"></div>
<div class="xm2">
<h1 class="fl">信息管理</h1>
</div>
<div class="xm2_b" style="border-bottom:0px;">
<div class="t">
	<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
	<td>
	<div class="an1"><a href="yx_vpp_caipiao.php?type=<?php echo $type ?>">信息管理</a></div>
	<div class="an2"><a href="yx_vpp_caipiao.php?action=add&type=<?php echo $type ?>">添加信息</a></div>
	<div class="an2"><a href="yx_vpp_caipiao.php?isok=1&type=<?php echo $type ?>">已审核</a></div>
	<div class="an2"><a href="yx_vpp_caipiao.php?isok=0&type=<?php echo $type ?>">未审核</a></div>
	</td>
	</tr>
	</table>
</div>

<div class="xm2_b">
<div class="height10"></div>
<table width="100%" border="0" cellpadding="8" cellspacing="1" class="table_southidc">
<form name="form1" method="post" action="yx_vpp_article.php?action=work&type=<?php echo "$type&$s"?>">
  <tr>
    <th width="4%" height="27" align="center"></th>
    <th width="6%" align="center">ID</th>
    <th width="25%" align="center"><?php echo $typename; ?>名称</th>
    <th width="25%" align="center">领取时间</th>
    <th width="10%" align="center">每天次数</th>
    <th width="10%" align="center">审核状态</th>
    <th width="20%" align="center">管理操作</th>
  </tr>
<?php
	$s="&type=".$type;
	$str=" and type = ".$type;
	if ($isok!=""){
		$istop=intval($istop);
		$str.=" and isok='$isok'";
		$s.="isok=$isok&";
	}

  if(empty($pageindex)){
      $pageindex=1;
  }
  $pagesize=intval($pagesize);
  if ($pagesize<=0){$pagesize=20;}

  $table=" mx_vpp_caipiao ";
  $order=" order by createdate desc, id desc";
  $column=" * ";
  $biaoid="id";
  $c=$db->listcount($table,$str);

  $list=$db->list1($pageindex,$pagesize,$table,$column,$str,$order,$biaoid);
	
	
  if (!is_array($list) or $c==0){
  echo "<tr class=\"list\"><td colspan=7><center>暂无信息</center></td></tr>";
  }
  else{
  for($i=0;$i<count($list);$i++){
		$list[$i][isok]=$list[$i][isok]?"<A HREF='?action=work&jobs=unisok&id=".$list[$i][id]."' title=取消审核>√</A>":"<A HREF='?action=work&jobs=isok&id=".$list[$i][id]."' style='color:blue;' title=审核通过>X</A>";
  ?>
  <tr class="list"> 
    <td width="4%" align="center">
      <input type="checkbox" name="listdb[<?php echo $list[$i][id] ?>]" value="<?php echo $list[$i][id] ?>" class="input_check"/>    </td>
    <td width="6%" align="center"><?php echo $list[$i][id]?></td>
    <td width="25%"><a href="yx_vpp_caipiao.php?id=<?php echo $list[$i][id]?>&action=edit"><?php echo $list[$i][name]?></a></td>
    <td align="center" width="30%"><?php echo $list[$i][startdate].' -- '.$list[$i][enddate] ?></td>
    <td align="center"><?php echo $list[$i][usernum]?></td>
    <td align="center"><?php echo $list[$i][isok]?></td>
    <td align="center">
        <a href="yx_vpp_caipiao_son.php?type=<?php echo $type ?>&cpid=<?php echo $list[$i][id]?>">奖项</a>
        <a href="yx_vpp_caipiao_log.php?cpid=<?php echo $list[$i][id]?>">记录</a>
        <a href="yx_vpp_caipiao.php?type=<?php echo $type ?>&id=<?php echo $list[$i][id]?>&action=edit">修改</a> 
        <a href="yx_vpp_caipiao.php?action=work&jobs=delete&id=<?php echo $list[$i][id]?>">删除</a> 
  </td>
  </tr>
<?php
	}
	}
?>
<input type="hidden" name="jobs" value="0">
</form>
</table>
<?php if ($c>0){?>
			<div class="height15"></div>
			<div class="do_div">
				<div class="l"><a href="javascript:CheckAll(document.form1,'all')">全选</a>&nbsp;<a href="javascript:CheckAll(document.form1,'')">反选</a></div>
				<div class="l2">
				选择操作：
				<a href="javascript:postdo('isok')">审核</a>
				<a href="javascript:postdo('unisok')">取消审核</a>
				<a href="javascript:postdo('delete')"/>删除</a>
				</div>
			</div>
			<div class="clear"></div>
			<div class="pagination">
			<?PHP
			echo $db->ThePage_mxsoft($s,$pageindex,$c,$pagesize)
			?>
			</div>
<?php }?>
<div class="clear"></div>
<div class="height10"></div>
<div class="clear"></div>
<script type="text/javascript" src="/mxsoft/js/jquerys-1.5.1.js"></script>
<script language="javascript">
$(document).ready(function(){  
	$(".table_southidc tr").mouseover(function(){   
	$(this).addClass("list2");}).mouseout(function(){   
	$(this).removeClass("list2");}) //移除该行的class   
	$(".table_southidc tr:even").addClass("list1");   
});   
</script> 

<script language="javascript">
function postdo(va){
	document.form1.jobs.value=va
	document.form1.submit();
}
function doDelete(id){
if(confirm("您确认要删除这些记录吗?")){
		document.form1.action="yx_vpp_article.php?reqCode=delete&channel=mh&bs=mh&at=&sort=&searchbs=&ssort=&kword=&zhuan=z&m=&type=<?php echo $type;?>chkid="+id;
		document.form1.submit();
	
}else{
return;
}
}
</script>
</div>
<?php require("../mx_foot.php");?>
</div>
</body>
</html>
